{template 'web/common/common'}
{template 'web/order/navbar'}

<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/layui.css" />
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/new-common.css" />
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">组团订单</div>
                <div class="layui-card-body">
                    <form id="myform" action="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>$_GPC['status'],'version_id'=>$_GPC['version_id'])}" method="post">
                        <div class="layui-form-item">
                            <input type="text" style="width: 200px;float: left;margin-right: 20px;height: 34px;" name="order_number" lay-verify="title" autocomplete="off" placeholder="订单编号" class="layui-input">
                            {php echo tpl_form_field_daterange('time', $old_time, $time = false);}
                            <input type="hidden" name="flag" value="">
                            <input type="hidden" name="order_type" value="1">
                            <button type="submit" id="submitForm" class="layui-btn" style="height: 34px;line-height: 34px;">搜索</button>
                            <a class="layui-btn" id="outOrder" href="#">批量导出</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>8,'version_id'=>$_GPC['version_id'])}" ><li class="{if $status==8}layui-this{/if}">全部</li></a>
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>7,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==7}layui-this{/if}">未支付</li></a>
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>1,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==1}layui-this{/if}">已支付</li></a>

        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>6,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==6}layui-this{/if}">组团中</li></a>

        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>2,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==2}layui-this{/if}">已发货</li></a>
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>3,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==3}layui-this{/if}">已完成</li></a>
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>4,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==4}layui-this{/if}">申请取消</li></a>
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','status'=>5,'version_id'=>$_GPC['version_id'])}"><li class="{if $status==5}layui-this{/if}">已取消</li></a>
        <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_order','is_recycel'=>1,'version_id'=>$_GPC['version_id'])}"><li class="{if $is_recycel==1}layui-this{/if}">回收站</li></a>
    </ul>
</div>

<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="50">
            <col width="100">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>订单编号</th>
            <th>订单总价</th>
            <th>优惠金额</th>
            <th>实际支付金额</th>
            <th>下单时间</th>
            <th>支付时间</th>
            <th>订单状态</th>
            <th>商户订单号</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {loop $list $key $item}
            <tr>
                    <td><span>{$item['id']}</span></td>
                    <td><span>{$item['order_number']}</span></td>
                    <td><span>￥{$item['total_price']}（含运费：￥{$item['send_price']}）</span></td>
                    <td><span>￥{$item['coupon_price']}</span></td>
                    <td><span>￥{$item['pra_price']}</span></td>
                    <td><span><?php echo date("Y-m-d H:i:s",$item['create_time']);?></span></td>
                    <td><span>
                        {if $item['pay_time']==0}
                        --：--
                        {else}
                        <?php echo date("Y-m-d H:i:s",$item['create_time']);?>
                        {/if}
                    </span></td>
                    <td><span>
                        {if $item['status']==0}
                        <span class="layui-badge layui-bg-gray">未支付</span>
                        {else if $item['status']==1}
                        <span class="layui-badge layui-bg-green">已支付</span>
                        {else if $item['status']==2}
                        <span class="layui-badge layui-bg-green">待收货</span>
                        {else if $item['status']==3}
                        <span class="layui-badge layui-bg-green">已完成</span>
                        {else if $item['status']==5}
                        <span class="layui-badge layui-bg-gray">已取消</span>
                        {else if $item['status']==4}
                        <a href="{url 'site/entry/refund',array('m'=>'kundian_farm','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}">
                            <button type="button" class="cancel-order layui-btn layui-btn-danger">确认取消订单</button></a>
                        {/if}
                    </span>
                    </td>
                <td>{$item['uniontid']}</td>
                <td>
                    <a href="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'group_edit','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}">
                        <button class="layui-btn layui-btn-xs">详情</button>
                    </a>
                    {if $item['is_recycle']==1}
                    <button class="layui-btn layui-btn-xs move_into_recycel" data-id="{$item['id']}" data-type="2">移出回收站</button>
                    {else}
                    <button class="layui-btn layui-btn-xs move_into_recycel" data-id="{$item['id']}" data-type="1">移入回收站</button>
                    {/if}
                </td>

            </tr>
        {/loop}
        </tbody>
    </table>
    <span>订单总金额：</span><span style="color: red;font-size: 20px;">￥{$totalMoney}</span>
    <div style="text-align: right;">
        {$pager}
    </div>
</div>


<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){

            $(".move_into_recycel").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                var type=$(this).attr('data-type');
                if(type==1){
                    var title="确定移入回收站吗?";
                }else{
                    var title="确定移出回收站吗?";
                }
                swal({
                    title: '提示',
                    text: title,
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'move_into_group_recycel','version_id'=>$_GPC['version_id'])}",
                            data:{order_id:id,type:type},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else if(res.status==3){
                                    swal("提示",'该订单未完成','error');
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });

            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '提示',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'deleteGroupOrder','version_id'=>$_GPC['version_id'])}",
                            data:{order_id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else if(res.status==3){
                                    swal("提示",'该订单未完成','error');
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });

            $("#submitForm").click(function () {
                $("input[name='flag']").val('');
                $("#myform").submit();    //提交ID为myform的表单
            })

            $("#outOrder").click(function () {
                $("input[name='flag']").val('true');
                $("#myform").submit();    //提交ID为myform的表单
            })
        })
    })
</script>